package com.work.yshop.mvp.presenter;

import com.work.yshop.R;
import com.work.yshop.mvp.contract.MainContract;

/**
 * 主页面的Presenter实现类
 */
public class MainPresenter extends MainContract.Presenter {

    // 页面索引
    private static final int PAGE_HOME = 0;
    private static final int PAGE_AGRI_TECH = 1;
    private static final int PAGE_MESSAGE = 2;
    private static final int PAGE_PROFILE = 3;

    @Override
    public boolean onNavigationItemSelected(int itemId) {
        if (itemId == R.id.navigation_home || itemId == R.id.navigation_seller_home) {
            view.switchToPage(PAGE_HOME);
            return true;
        } else if (itemId == R.id.navigation_agri_tech || itemId == R.id.navigation_agri_circle) {
            view.switchToPage(PAGE_AGRI_TECH);
            return true;
        } else if (itemId == R.id.navigation_message) {
            view.switchToPage(PAGE_MESSAGE);
            return true;
        } else if (itemId == R.id.navigation_profile) {
            view.switchToPage(PAGE_PROFILE);
            return true;
        }
        return false;
    }

    @Override
    public void onPublishButtonClicked() {
        // 通知View层进行发布页面跳转
        // 在MVP架构中，跳转操作也需要通过View层来实现
        if (isViewAttached()) {
            // 需要在MainContract.View中定义相应方法
            if (view instanceof MainContract.View) {
                ((MainContract.View) view).navigateToPublish();
            }
        }
    }
} 